package gosu;

import java.awt.color.*;

public class Color {
  public static Color none = new Color(0x00000000);
  public static Color black = new Color(java.awt.Color.black);
  public static Color gray = new Color(java.awt.Color.gray);
  public static Color white = new Color(java.awt.Color.white);
  public static Color red = new Color(java.awt.Color.red);
  public static Color green = new Color(java.awt.Color.green);
  public static Color blue = new Color(java.awt.Color.blue);
  public static Color yellow = new Color(java.awt.Color.yellow);
  public static Color fuschia = new Color(0xffff00ff);
  public static Color cyan = new Color(java.awt.Color.cyan);
  

  private java.awt.Color _color;


  public Color(java.awt.Color color) {
    _color = color;
  }

  public Color(int argb) {
    _color = new java.awt.Color(argb, true);
  }


  public Color(int r, int g, int b) {
    _color = new java.awt.Color(r, g, b);
  }


  public Color(int a, int r, int g, int b) {
    _color = new java.awt.Color(r, g, b, a);
  }


  public int alpha() { return _color.getAlpha(); }
  public int red() { return _color.getRed(); }
  public int green() { return _color.getGreen(); }
  public int blue() { return _color.getBlue(); }


  public void setAlpha(int alpha) {
    _color = new java.awt.Color(_color.getRed(), _color.getGreen(), _color.getBlue(), alpha);
  }


  public void setRed(int red) {
    _color = new java.awt.Color(red, _color.getGreen(), _color.getBlue(), _color.getAlpha());
  }


  public void setGreen(int green) {
    _color = new java.awt.Color(_color.getRed(), green, _color.getBlue(), _color.getAlpha());
  }


  public void setBlue(int blue) {
    _color = new java.awt.Color(_color.getRed(), _color.getGreen(), blue, _color.getAlpha());
  }


  public double hue() { return toHSV()[0] * 360.0; }
  public double saturation() { return toHSV()[1]; }
  public double value() { return toHSV()[2]; }


  public void setHue(float hue) {
    float hsb[] = toHSV();
    _color = java.awt.Color.getHSBColor(hue / 360.0f, hsb[1], hsb[2]);
  }


  public void setSaturation(float saturation) {
    float hsb[] = toHSV();
    _color = java.awt.Color.getHSBColor(hsb[0], saturation, hsb[2]);
  }


  public void setValue(float value) {
    float hsb[] = toHSV();
    _color = java.awt.Color.getHSBColor(hsb[0], hsb[1], value);
  }


  public java.awt.Color getAWTColor() { return _color; }


  public static Color fromHSV(float h, float s, float v) {
    return fromAHSV(255, h, s, v);
  }


  public static Color fromAHSV(int alpha, float h, float s, float v) {
    java.awt.Color c = java.awt.Color.getHSBColor(h/360.0f, s, v);
    return new Color(alpha, c.getRed(), c.getGreen(), c.getBlue());
  }


  private float[] toHSV() {
    return java.awt.Color.RGBtoHSB(_color.getRed(), _color.getGreen(), _color.getBlue(), null);
  }
}

